package com.jkl.untils.excel;

import java.util.Arrays;

/**
 * @Author zhukangkang
 * @Description 功能说明: 用来存储Excel标题的对象，通过该对象可以获取标题和方法的对应关系
 * @Date 2019-09-23
 **/
public class ExcelHeader implements Comparable<ExcelHeader> {

    // excel的标题名称
    private String title;

    // 每一个标题的顺序
    private int order;

    // 注解域
    private String filed;

    // 属性类型
    private Class<?> filedClazz;

    // 数据字典 key
    private String[] dicKey;

    // 数据字典 value
    private String[] dicValue;

    // 是否导出列
    private boolean export;

    // 是否主键
    private boolean pk;

    // 是否自增
    private boolean increase;

    // 列宽度
    private int width;

    public String getTitle() {
        return title;
    }

    public int getOrder() {
        return order;
    }

    public String getFiled() {
        return filed;
    }

    public Class<?> getFiledClazz() {
        return filedClazz;
    }

    public String[] getDicKey() {
        return dicKey;
    }

    public String[] getDicValue() {
        return dicValue;
    }

    public int getWidth() {
        return width;
    }

    public boolean isExport() {
        return export;
    }

    public boolean isPk() {
        return pk;
    }

    public boolean isIncrease() {
        return increase;
    }

    public static class Builder{
        private String title;
        private int order;
        private String filed;
        private Class<?> filedClazz;
        private String[] dicKey;
        private String[] dicValue;
        private boolean export;
        private boolean pk;
        private boolean increase;
        private int width;

        public Builder title(String title) {
            this.title = title;
            return this;
        }

        public Builder order(int order) {
            this.order = order;
            return this;
        }

        public Builder filed(String filed) {
            this.filed = filed;
            return this;
        }

        public Builder filedClazz(Class<?> filedClazz) {
            this.filedClazz = filedClazz;
            return this;
        }

        public Builder dicKey(String[] dicKey) {
            this.dicKey = dicKey;
            return this;
        }

        public Builder dicValue(String[] dicValue) {
            this.dicValue = dicValue;
            return this;
        }

        public Builder export(boolean export) {
            this.export = export;
            return this;
        }

        public Builder pk(boolean pk) {
            this.pk = pk;
            return this;
        }

        public Builder increase(boolean increase) {
            this.increase = increase;
            return this;
        }

        public Builder width(int width) {
            this.width = width;
            return this;
        }

        public ExcelHeader build(){
            return new ExcelHeader(this);
        }
    }
    public ExcelHeader() {}

    private ExcelHeader(Builder builder){
        this.title = builder.title;
        this.order = builder.order;
        this.filed = builder.filed;
        this.filedClazz = builder.filedClazz;
        this.dicKey = builder.dicKey;
        this.dicValue = builder.dicValue;
        this.export = builder.export;
        this.pk = builder.pk;
        this.increase = builder.increase;
        this.width = builder.width;
    }

    @Override
    public int compareTo(ExcelHeader o) {
        return order - o.order;
    }

    @Override
    public String toString() {
        return "ExcelHeader{" +
                "title='" + title + '\'' +
                ", order=" + order +
                ", filed='" + filed + '\'' +
                ", filedClazz=" + filedClazz +
                ", dicKey=" + Arrays.toString(dicKey) +
                ", dicValue=" + Arrays.toString(dicValue) +
                ", export=" + export +
                ", pk=" + pk +
                ", increase=" + increase +
                '}';
    }
    public void setTitle(String title) {
        this.title = title;
    }
}

